﻿package _8_JDialog;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
 * 2011-6-7 15:23:00
 * @author Administrator
 */
public class TJDialog {
    JFrame frame;
    Container contentPane;
    JButton showButton;
    public TJDialog(){
        frame=new JFrame("对话框测试");
        contentPane=frame.getContentPane();
        showButton=new JButton("弹出对话框");
        showButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JDialog dialog=new JDialog(frame);
                dialog.setSize(new Dimension(400,400));
                dialog.setLocationRelativeTo(frame);
                dialog.setModal(true);
                dialog.setVisible(true);
//                JOptionPane.showInternalConfirmDialog(frame.getContentPane(), "Hello");
            }
        });
        contentPane.setLayout(new FlowLayout());
        contentPane.add(showButton);
        frame.setSize(new Dimension(800,600));
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
    public static void main(String args[]){
        new TJDialog();
    }
}
